﻿//********************************************************************************//
//创建日期：<创建日期，2016-05-06>
//创建作者：<郭登杰>
//功能说明：来函公共控件-操作按钮
//********************************************************************************//

using System;
using System.Web.UI;
using BLL;
using BLL.Access;
using DevExpress.Web;
using Entity;
using Web.Class;
using System.Collections.Generic;
using System.Data;

namespace Web.Controls.LAIHAN
{
    public partial class UCLHSJBTNS : UserControl, IUCLHOperate
    {
        #region 属性

        /// <summary>
        ///     来函ID
        /// </summary>
        public string LaiHanID
        {
            get { return hdCollection.Contains("LaiHanID") ? Convert.ToString(hdCollection.Get("LaiHanID")) : ""; }
            set { hdCollection.Set("LaiHanID", value); }
        }

        /// <summary>
        ///     来函类型
        /// </summary>
        public eLaiHanLX LaiHanLX { get; set; }

        #endregion

        #region 事件

        /// <summary>
        ///     页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                InitControl();
        }

        /// <summary>
        ///     响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, CallbackEventArgs e)
        {
            if (e.Parameter=="sj")
            {
                //var rs = LaiHanLCTools.ValidateInfoDJ(Parent);
                //if (!rs.IsSuccess)
                //{
                //    e.Result = string.Join("|", e.Parameter, "-1", rs.Msg);
                //    return;
                //}
                e.Result = e.Parameter + "|" + AddLAIHANXX(e.Parameter == "sj" ? 0 : 1);
            }
            if (e.Parameter=="sjdj")
            {
                var rs = LaiHanLCTools.ValidateInfoDJ(Parent);
                if (!rs.IsSuccess)
                {
                    e.Result = string.Join("|", e.Parameter, "-1", rs.Msg);
                    return;
                }
                e.Result = e.Parameter + "|" + AddLAIHANXX(e.Parameter == "sj" ? 0 : 1);
            }
            else if (e.Parameter == "tjbsx") //不走流程,提交后直接生效
            {
                var strT = AddLAIHANXX(1);
                LaiHanID = strT.Split('|')[2];
                if (string.IsNullOrEmpty(LaiHanID))
                {
                    e.Result = string.Join("|", e.Parameter, "-1", "缺少参数。");
                    return;
                }
                var bllT = new YS_LH_LAIHANXXProcess();
                var laihan = bllT.SelectYS_LH_LAIHANXX(int.Parse(LaiHanID));
                if (laihan == null)
                {
                    e.Result = string.Join("|", e.Parameter, "-1", "参数不正确。");
                    return;
                }
                //判断申请理由控件是否存在,有则记录信息
                var uc = Parent.FindControl("UCLHShenQingLY") as UCLHShenQingLY;
                if (uc != null)
                {
                    laihan.S_SHENQINGLY = uc.LiYou;
                    laihan.S_BEIZHU = uc.BeiZhu;
                }
                laihan.I_LIUCHENGBH = (int)eLaiHanLCBH.登记;
                laihan.I_LIUCHENGZT = (int)eLaiHanLCZT.通过;
                bllT.InsertOrUpdate(laihan);
                LaiHanLCTools.AddNextFlow(laihan, eLaiHanSPJG.同意, true);
                //操作成功
                e.Result = string.Join("|", e.Parameter, "0", "操作成功");
            }
            else if (e.Parameter.Contains("sl") || e.Parameter == "th")
            {
                if (string.IsNullOrEmpty(LaiHanID))
                {
                    e.Result = string.Join("|", e.Parameter, "-1", "缺少参数。");
                    return;
                }
                var bllT = new YS_LH_LAIHANXXProcess();
                var laihan = bllT.SelectYS_LH_LAIHANXX(int.Parse(LaiHanID));
                if (laihan == null)
                {
                    e.Result = string.Join("|", e.Parameter, "-1", "参数不正确。");
                    return;
                }
                var lcbh = e.Parameter == "th"
                    ? eLaiHanLCBH.退回 //退回
                    : e.Parameter == "sl"
                        ? eLaiHanLCBH.受理 //受理
                        : e.Parameter == "bsl"
                            ? eLaiHanLCBH.不受理 //不受理
                            : eLaiHanLCBH.受理;

                laihan.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
                laihan.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                if (lcbh == eLaiHanLCBH.受理)
                {

                    laihan.I_LIUCHENGBH = (int)eLaiHanLCBH.受理;
                    laihan.I_LIUCHENGZT = (int)eLaiHanLCZT.流程中;
                }
                else if (lcbh == eLaiHanLCBH.不受理)
                {
                    laihan.I_LIUCHENGZT = (int)eLaiHanLCZT.不受理;
                    laihan.I_LIUCHENGBH = (int)eLaiHanLCBH.登记;  // 来函登记界面 不受理按钮 流程编号变动
                }
                else if (lcbh == eLaiHanLCBH.退回)
                {
                    laihan.I_LIUCHENGBH = (int)eLaiHanLCBH.预登记;
                    laihan.I_LIUCHENGZT = (int)eLaiHanLCZT.流程中;
                }
                if (laihan.I_LIUCHENGBH == (int)eLaiHanLCBH.受理)//20190325 修改条件2->eLaiHanLCBH.受理
                {
                    if (LaiHanLX == eLaiHanLX.月度 || LaiHanLX == eLaiHanLX.年度 || LaiHanLX == eLaiHanLX.基建调整 ||
                        LaiHanLX == eLaiHanLX.计划变更)
                    {
                        new SqlHelper().AddLaiHanSpx(laihan.S_LAIHANBH, null);
                    }
                }

                bllT.InsertOrUpdate(laihan);
                //记录流程_受理
                var lcbllT = new YS_LH_LAIHANLCJLProcess();
                var lcjl = new YS_LH_LAIHANLCJL();
                lcjl.D_CAOZUORQ = DateTime.Now;
                lcjl.D_STARTDATE = DateTime.Now;
                lcjl.D_ENDDATE = DateTime.Now;
                lcjl.I_CAOZUOR = LoginInfo.CurrentUser.UserID;
                lcjl.I_LAIHANLX = (int)LaiHanLX;
                lcjl.I_LIUCHENGBH = (int)lcbh;
                lcjl.ID = 0;
                lcjl.S_LAIHANBH = laihan.S_LAIHANBH;
                lcjl.S_LIUCHENGMC = lcbh.ToString();
                lcbllT.InsertOrUpdate(lcjl);
                //如果是受理,插入下一步流程
                if (lcbh == eLaiHanLCBH.受理)
                    LaiHanLCTools.AddNextFlow(laihan, eLaiHanSPJG.同意, false);
                //操作成功
                e.Result = string.Join("|", e.Parameter, "0", "操作成功");
            }
        }

        /// <summary>
        ///     前台验证后实际执行后台操作
        /// </summary>
        protected void btnActPerform_Click(object sender, EventArgs e)
        {
            //收件操作成功后重新加载数据
            if (hdCollection.Get("type").ToString().Contains("sj"))
            {
                Session["gaopai"] = null;
                var laihanxx = new YS_LH_LAIHANXXProcess().SelectYS_LH_LAIHANXX(decimal.Parse(LaiHanID));
                var ucinfo = Parent.FindControl("UCLHUserInfo") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHUserInfo_BH") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHShenQingLY") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHBiaoInfoQS") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                if (this.LaiHanLX == eLaiHanLX.水资源深井类型修改 || this.LaiHanLX == eLaiHanLX.水资源井性质修改 || this.LaiHanLX == eLaiHanLX.水资源注销井恢复)
                {
                    ucinfo = Parent.FindControl("UCLHJinInfo2QS") as IUCLHOperate;
                    ucinfo.LoadInfo(laihanxx);
                    ucinfo = Parent.FindControl("UCLHJinListQS") as IUCLHOperate;
                    ucinfo.LoadInfo(laihanxx);
                }
                ucinfo = Parent.FindControl("UCLHJinInfoQS") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHJinInfo2QS") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHKaiCaiJHQS") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHCaiGuanJHQS") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHJiaJiaSLInfoQS") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHTuiKuanInfoQS") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                //取水分户
                ucinfo = Parent.FindControl("UCLHFenHuQS") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                if (LaiHanLX == eLaiHanLX.分户)
                {
                    ucinfo = Parent.FindControl("UCLHFenHuDJXX") as IUCLHOperate;
                    if (ucinfo != null)
                        ucinfo.LoadInfo(laihanxx);
                    //多分户添加 20190426
                    ucinfo = Parent.FindControl("UCLHShenQingXX_FH") as IUCLHOperate;
                    if (ucinfo != null)
                        ucinfo.LoadInfo(laihanxx);
                }
                else
                {
                    ucinfo = Parent.FindControl("UCLHShenQingXX") as IUCLHOperate;
                    if (ucinfo != null)
                        ucinfo.LoadInfo(laihanxx);
                }
                ucinfo = Parent.FindControl("UCLHShenQingXX_YDTZ") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHShenQingXX_JHBG") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHShenQingXX_BH") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHShenQingXX_BHQS") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                //改户
                ucinfo = Parent.FindControl("UCLHGaiHuTopInfo") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                //材料上传
                ucinfo = Parent.FindControl("UCLHBtnBottom") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHCaiLiaoInfo") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);

                ucinfo = Parent.FindControl("UCLHShuiBiaoList") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHShenQingXX_TK") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHShuiBiaoListQS") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);
                ucinfo = Parent.FindControl("UCLHSJBTNS") as IUCLHOperate;
                if (ucinfo != null)
                    ucinfo.LoadInfo(laihanxx);

                SetDisplay(laihanxx);
            }
            else if (hdCollection.Get("type").ToString().Contains("sl"))
            {
                BtnSL.ClientEnabled = false;
                BtnBSL.ClientEnabled = true;
            }
        }

        #endregion

        #region 方法

        /// <summary>
        ///     控置显示
        /// </summary>
        private void SetDisplay(YS_LH_LAIHANXX laihanxx)
        {
            if (laihanxx.ID == 0 || laihanxx.I_LIUCHENGBH == (int)eLaiHanLCBH.预登记)
            {
                //this.btnFQ.Visible = true;
                btnSJ.Visible = true;
                btnALL.Visible = true;
                BtnBack.Visible = false;
                BtnBSL.Visible = true;
                BtnSL.Visible = false;
                if (BusinessTool.WType == 1 && LoginInfo.CurrentUser.UserID == 113 && LaiHanLX == eLaiHanLX.水资源销表)
                    btnOver.Visible = true;
                else
                    btnOver.Visible = false;
            }
            else
            {
                //this.btnFQ.Visible = true;
                btnSJ.Visible = false;
                btnALL.Visible = false;
                BtnBack.Visible = true;
                BtnBSL.Visible = true;
                BtnSL.Visible = true;
                btnOver.Visible = false;
            }
        }

        /// <summary>
        ///     添加来函
        /// </summary>
        /// <param name="liuchengbh">0:收件 1:收件齐全并登记 </param>
        private string AddLAIHANXX(int liuchengbh)
        {
            var isAdd = string.IsNullOrEmpty(LaiHanID) || LaiHanID == "" || LaiHanID == "0";
            var laihanxxBLL = new YS_LH_LAIHANXXProcess();
            //添加来函主表
            YS_LH_LAIHANXX laihan = null;
            //审核通过后更新用户信息 现在记录在来函用户信息表中
            var lhyonghuxxbll = new YS_LH_YONGHUXXProcess();
            YS_LH_YONGHUXX lhyhxx = null;
            var msg = "";
            if (LaiHanLX == eLaiHanLX.年度 || LaiHanLX == eLaiHanLX.基建调整 || LaiHanLX == eLaiHanLX.计划变更 || LaiHanLX == eLaiHanLX.表计因素注销
                || LaiHanLX == eLaiHanLX.计划指标注销
                || LaiHanLX == eLaiHanLX.计划转移//有独立的控件
                || LaiHanLX == eLaiHanLX.月度 || LaiHanLX == eLaiHanLX.销户 || LaiHanLX == eLaiHanLX.销表 ||
                LaiHanLX == eLaiHanLX.退款
                || LaiHanLX == eLaiHanLX.水资源销户)
            {
                var userinfo = Parent.FindControl("UCLHUserInfo") as UCLHUserInfo;
                laihan = userinfo.GetLAIHANXX(int.Parse(LaiHanID == "" ? "0" : LaiHanID), liuchengbh, out msg);
                if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH, laihan.S_YONGHUBH,
                    Convert.ToString(laihan.I_Y), Convert.ToString(laihan.I_M), out msg))
                    return "-1|" + msg;
                if (laihan != null)
                    lhyhxx = userinfo.GetLHYONGHUXX(laihan);
            }
            else if ((LaiHanLX == eLaiHanLX.水资源销井) || LaiHanLX == eLaiHanLX.水资源井过户)
            {
                var userinfo = Parent.FindControl("UCLHJinInfoQS") as UCLHJinInfoQS;
                laihan = userinfo.GetLAIHANXX(int.Parse(LaiHanID == "" ? "0" : LaiHanID), liuchengbh, out msg);
                if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH, laihan.S_YONGHUBH,
                    Convert.ToString(laihan.I_Y), Convert.ToString(laihan.I_M), out msg))
                    return "-1|" + msg;
                if (laihan != null)
                    lhyhxx = userinfo.GetLHYONGHUXX(laihan);
            }
            else if (LaiHanLX == eLaiHanLX.改户)
            {
                var uc = Parent.FindControl("UCLHGaiHuTopInfo") as UCLHGaiHuTopInfo;
                if (uc != null)
                {
                    laihan = uc.GetLaiHanXX(isAdd, liuchengbh);
                    if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH,
                        laihan.S_YONGHUBH, "", "", out msg))
                        return "-1|" + msg;
                }
            }
            else if (LaiHanLX == eLaiHanLX.分户)
            {
                var uc = Parent.FindControl("UCLHFenHuDJXX") as UCLHFenHuDJXX;
                if (uc != null)
                {
                    laihan = uc.GetLaiHanXX(isAdd, liuchengbh);
                    if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH,
                        laihan.S_YONGHUBH, "", "", out msg))
                        return "-1|" + msg;
                }
                //20190425 多分户添加
                var ucmfh = Parent.FindControl("UCLHShenQingXX_FH") as UCLHShenQingXX_FH;
                if (ucmfh != null)
                {
                    laihan = ucmfh.GetLaiHanXX(isAdd, liuchengbh);
                    if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH,
                        laihan.S_YONGHUBH, "", "", out msg))
                        return "-1|" + msg;
                }
            }
            else if (LaiHanLX == eLaiHanLX.并户)
            {
                //验证当前要并的用户是否也其他来函流程中,存在则无法并户
                var ucShenQingXX = Page.FindControl("UCLHShenQingXX_BH") as UCLHShenQingXX_BH;
                laihan = ucShenQingXX.GetLAIHANXX(int.Parse(LaiHanID == "" ? "0" : LaiHanID), liuchengbh, out msg);
                var yonghuhList = ucShenQingXX.GetYonghuhList();
                var yonghuhs = string.Join(",", yonghuhList);
                if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH, yonghuhs, null,
                    null, out msg))
                    return "-1|" + msg;
                lhyhxx = null;
            }
            else if (LaiHanLX == eLaiHanLX.水资源并户)
            {
                //验证当前要并的用户是否也其他来函流程中,存在则无法并户
                var ucShenQingXX = Page.FindControl("UCLHShenQingXX_BHQS") as UCLHShenQingXX_BHQS;
                laihan = ucShenQingXX.GetLAIHANXX(int.Parse(LaiHanID == "" ? "0" : LaiHanID), liuchengbh, out msg);
                var yonghuhList = ucShenQingXX.GetYonghuhList();
                var yonghuhs = string.Join(",", yonghuhList);
                if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH, yonghuhs, null,
                    null, out msg))
                    return "-1|" + msg;
                lhyhxx = null;
            }
            else if (LaiHanLX == eLaiHanLX.水资源销表 || LaiHanLX == eLaiHanLX.水资源表过户)
            {
                //验证当前要并的用户是否也其他来函流程中,存在则无法并户
                var ucShenQingXX = Page.FindControl("UCLHShuiBiaoListQS") as UCLHShuiBiaoListQS;
                laihan = ucShenQingXX.GetLAIHANXX(int.Parse(LaiHanID == "" ? "0" : LaiHanID), liuchengbh, out msg);
                if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH, laihan.S_YONGHUBH,
                    Convert.ToString(laihan.I_Y), Convert.ToString(laihan.I_M), out msg))
                    return "-1|" + msg;
                if (LaiHanLX == eLaiHanLX.水资源销表)
                {
                    UCLHShenQingLY sqly = this.Parent.FindControl("UCLHShenQingLY") as UCLHShenQingLY;
                    if (sqly != null)
                    {
                        laihan.S_SHENQINGLY = sqly.LiYou;
                    }
                }
                lhyhxx = null;
            }
            else if (LaiHanLX == eLaiHanLX.水资源深井类型修改 || LaiHanLX == eLaiHanLX.水资源井性质修改 || LaiHanLX == eLaiHanLX.水资源注销井恢复)
            {
                //验证当前要并的用户是否也其他来函流程中,存在则无法并户
                var ucShenQingXX = Page.FindControl("UCLHJinListQS") as UCLHJinListQS;
                laihan = ucShenQingXX.GetLAIHANXX(int.Parse(LaiHanID == "" ? "0" : LaiHanID), liuchengbh, out msg);
                /*
                if (LaiHanLCTools.HasRelationExists((int) LaiHanLX, isAdd ? null : laihan.S_LAIHANBH, laihan.S_YONGHUBH,
                    Convert.ToString(laihan.I_Y), Convert.ToString(laihan.I_M), out msg))
                    return "-1|" + msg;
                 * */
                lhyhxx = null;
            }
            else if (LaiHanLX == eLaiHanLX.水资源开采计划)
            {
                //验证当前要并的用户是否也其他来函流程中,存在则无法并户
                var ucShenQingXX = Page.FindControl("UCLHKaiCaiJHQS") as UCLHKaiCaiJHQS;
                laihan = ucShenQingXX.GetLAIHANXX(int.Parse(LaiHanID == "" ? "0" : LaiHanID), liuchengbh, out msg);
                if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH, laihan.S_YONGHUBH,
                    Convert.ToString(laihan.I_Y), Convert.ToString(laihan.I_M), out msg))
                    return "-1|" + msg;
                lhyhxx = null;
            }
            else if (LaiHanLX == eLaiHanLX.水资源采灌计划)
            {
                //验证当前要并的用户是否也其他来函流程中,存在则无法并户
                var ucShenQingXX = Page.FindControl("UCLHCaiGuanJHQS") as UCLHCaiGuanJHQS;
                laihan = ucShenQingXX.GetLAIHANXX(int.Parse(LaiHanID == "" ? "0" : LaiHanID), liuchengbh, out msg);
                if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH, laihan.S_YONGHUBH,
                    Convert.ToString(laihan.I_Y), Convert.ToString(laihan.I_M), out msg))
                    return "-1|" + msg;
                lhyhxx = null;
            }
            else if (LaiHanLX == eLaiHanLX.水资源加价水量调整)
            {
                //验证当前要并的用户是否也其他来函流程中,存在则无法并户
                var ucShenQingXX = Page.FindControl("UCLHJiaJiaSLInfoQS") as UCLHJiaJiaSLInfoQS;
                laihan = ucShenQingXX.GetLAIHANXX(int.Parse(LaiHanID == "" ? "0" : LaiHanID), liuchengbh, out msg);
                //if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH, laihan.S_YONGHUBH,
                //    Convert.ToString(laihan.I_Y), Convert.ToString(laihan.I_M), out msg))
                //    return "-1|" + msg;
                lhyhxx = null;
            }
            else if (LaiHanLX == eLaiHanLX.水资源退款)
            {
                //验证当前要并的用户是否也其他来函流程中,存在则无法并户
                var ucShenQingXX = Page.FindControl("UCLHTuiKuanInfoQS") as UCLHTuiKuanInfoQS;
                laihan = ucShenQingXX.GetLAIHANXX(int.Parse(LaiHanID == "" ? "0" : LaiHanID), liuchengbh, out msg);
                if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH, laihan.S_YONGHUBH,
                    Convert.ToString(laihan.I_Y), Convert.ToString(laihan.I_M), out msg))
                    return "-1|" + msg;
                lhyhxx = null;
            }
            else if (LaiHanLX == eLaiHanLX.水资源分户)
            {
                var ucShenQingXX = Page.FindControl("UCLHFenHuQS") as UCLHFenHuQS;
                laihan = ucShenQingXX.GetLAIHANXX(int.Parse(LaiHanID == "" ? "0" : LaiHanID), liuchengbh, out msg);
                var yhhList = ucShenQingXX.GetYHHList();
                for (var i = 0; i < yhhList.Count; i++)
                    if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH, yhhList[i],
                        Convert.ToString(laihan.I_Y), Convert.ToString(laihan.I_M), out msg))
                        return "-1|" + msg;
                lhyhxx = null;
            }
            else if (LaiHanLX == eLaiHanLX.水资源销取水口 || LaiHanLX == eLaiHanLX.水资源取水口过户)
            {
                //验证当前要并的用户是否也其他来函流程中,存在则无法并户
                var ucShenQingXX = Page.FindControl("UCLHJinInfoQS") as UCLHJinInfoQS;
                laihan = ucShenQingXX.GetLAIHANXX(int.Parse(LaiHanID == "" ? "0" : LaiHanID), liuchengbh, out msg);
                if (LaiHanLCTools.HasRelationExists((int)LaiHanLX, isAdd ? null : laihan.S_LAIHANBH, laihan.S_YONGHUBH,
                    Convert.ToString(laihan.I_Y), Convert.ToString(laihan.I_M), out msg))
                    return "-1|" + msg;
                lhyhxx = null;
            }
            //初次登记时验证上传资料 (非行政审批的不验证)
            if (isAdd)
            {
                var rs = new ValidateRS();
                var ucCaiLiao = Parent.FindControl("UCLHCaiLiaoInfo") as UCLHCaiLiaoInfo;
                UCLHBtnBottom ucCailiao2 = null;
                //ucCaiLiao.SelectedItems;
                if (ucCaiLiao != null)
                {
                    rs = ucCaiLiao.ValidateSubmit(laihan.S_LAIHANBH, laihan.S_YONGHUBH);
                }
                else
                {
                    ucCailiao2 = Parent.FindControl("UCLHBtnBottom") as UCLHBtnBottom;
                    rs = ucCailiao2.ValidateSubmit(laihan.S_LAIHANBH, laihan.S_YONGHUBH);
                }
                if (LaiHanLX==eLaiHanLX.月度||LaiHanLX==eLaiHanLX.年度||LaiHanLX==eLaiHanLX.基建调整||LaiHanLX==eLaiHanLX.计划变更||LaiHanLX==eLaiHanLX.计划转移)
                    if (!rs.IsSuccess)
                        return "-1|" + rs.Msg;
                //如果有新上传的文件信息插入数据库
                if (ucCaiLiao != null)
                    ucCaiLiao.SHOUJIAN(laihan);
                else
                    ucCailiao2.SHOUJIAN(laihan);
            }
            // 网上申请（需要验证材料是否完整）
            else if (laihan.I_SHURUR == 99996)
            {
                var rs = new ValidateRS();
                var ucCaiLiao = Parent.FindControl("UCLHCaiLiaoInfo") as UCLHCaiLiaoInfo;
                if (ucCaiLiao != null)
                {
                    rs = ucCaiLiao.ValidateSubmit(laihan.S_LAIHANBH, laihan.S_YONGHUBH);
                    ucCaiLiao.SHOUJIAN(laihan);
                    if (!rs.IsSuccess)
                        return "-1|" + rs.Msg;
                }
            }

            //// todo: 功能未完善前，暂时屏蔽异常;取消使用程序定时生成
            //try
            //{
            //    if (string.IsNullOrEmpty(laihan.S_TONGYIBM)
            //        && Helper.UnicodeHelper.IsNeedUnicode((eLaiHanLX)laihan.I_LAIHANLX))
            //    {
            //        laihan.S_TONGYIBM = Helper.UnicodeHelper.GetUnicode();
            //        Helper.UnicodeHelper.CreateScanCode(laihan);
            //    }
            //}
            //catch (Exception) { }

            //更新主表
            laihanxxBLL.InsertOrUpdate(laihan);

            //添加来函副表
            AddLaiHanFuBiao(liuchengbh, laihan);
            //添加来函用户表,有些并不更新此表,如并户
            if (lhyhxx != null)
                lhyonghuxxbll.InsertOrUpdate(lhyhxx);
            //添加或更新流程记录信息
            var lcbzbll = new YS_LH_LAIHANLCJLProcess();
            var lcjl = new YS_LH_LAIHANLCJL();
            lcjl.D_CAOZUORQ = DateTime.Now;
            lcjl.D_STARTDATE = DateTime.Now;
            lcjl.D_ENDDATE = DateTime.Now;
            lcjl.I_CAOZUOR = LoginInfo.CurrentUser.UserID;
            lcjl.I_LAIHANLX = (int)LaiHanLX;
            lcjl.I_LIUCHENGBH = liuchengbh;
            lcjl.ID = 0;
            lcjl.S_LAIHANBH = laihan.S_LAIHANBH;
            lcjl.S_LIUCHENGMC = liuchengbh == 1 ? "登记" : "预登记";
            //获取流程ID 20190426 add
            YS_LH_LAIHANLCJLBLL blllcjl = new YS_LH_LAIHANLCJLBLL();                
            DataTable lcxx = blllcjl.SelectYS_LH_LAIHANLCJLsDynamic(
                string.Format(" S_LAIHANBH='{0}' and I_LIUCHENGBH={1} ", laihan.S_LAIHANBH, lcjl.I_LIUCHENGBH),
                "", null);
            if (lcxx != null && lcxx.Rows.Count > 0)
                lcjl.ID = Convert.ToInt32(lcxx.Rows[0]["ID"]);

            var logText = LaiHanLX + (isAdd ? "登记" : "修改");
            new SYS_LOGBLL().Log(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), logText,
                isAdd ? OperateState.Add : OperateState.Modify, laihan, null);
            lcbzbll.InsertOrUpdate(lcjl);
            Session["gaopai"] = null;
            return "0|操作成功|" + laihan.ID;
        }

        /// <summary>
        ///     添加来函副表
        /// </summary>
        /// <param name="liuchengzt">流程状态</param>
        /// <param name="laihan">来函信息</param>
        private void AddLaiHanFuBiao(int liuchengzt, YS_LH_LAIHANXX laihan)
        {
            if (LaiHanLX == eLaiHanLX.月度)
            {
                var ucinfo = Parent.FindControl("UCLHShenQingXX_YDTZ") as UCLHShenQingXX_YDTZ;
                ucinfo.CreateShengQingXX(laihan);
            }
            else if (LaiHanLX == eLaiHanLX.年度)
            {
                //添加来函附表（年度调整）信息
                var niantiaozbll = new YS_LH_NIANTIAOZBLL();
                var tz = new YS_LH_NIANTIAOZ();
                tz.ID = 0;
                tz.D_SHURURQ = DateTime.Now;
                tz.I_JLZT = 0;
                tz.I_Y = Convert.ToInt32(laihan.I_TZY);
                tz.S_LAIHANBH = laihan.S_LAIHANBH;
                tz.S_YONGHUBH = laihan.S_YONGHUBH;
                tz.S_ZHANDIANBH = laihan.S_ZHANDIANBH;
                tz.I_SHURUR = LoginInfo.CurrentUser.UserID;
                //获取调整信息
                var ucShenQingXX = Parent.FindControl("UCLHShenQingXX") as UCLHShenQingXX;
                var listSqls = ucShenQingXX.GetSQLS(false);
                tz.I_M1 = listSqls[0];
                tz.I_M2 = listSqls[1];
                tz.I_M3 = listSqls[2];
                tz.I_M4 = listSqls[3];
                tz.I_M5 = listSqls[4];
                tz.I_M6 = listSqls[5];
                tz.I_M7 = listSqls[6];
                tz.I_M8 = listSqls[7];
                tz.I_M9 = listSqls[8];
                tz.I_M10 = listSqls[9];
                tz.I_M11 = listSqls[10];
                tz.I_M12 = listSqls[11];
                tz.I_LIUCHENGBH = liuchengzt;
                //有计划信息才会插入调整信息
                niantiaozbll.InsertOrUpdate(tz);
            }
            else if (LaiHanLX == eLaiHanLX.基建调整)
            {
                //添加来函附表（基建调整）信息
                var bllT = new YS_LH_JIJIANTZBLL();
                var tz = new YS_LH_JIJIANTZ();
                tz.ID = 0;
                tz.D_SHURURQ = DateTime.Now;
                tz.I_JLZT = 0;
                tz.I_Y = Convert.ToInt32(laihan.I_TZY);
                tz.S_LAIHANBH = laihan.S_LAIHANBH;
                tz.S_YONGHUH = laihan.S_YONGHUBH;
                tz.S_ZHANDIANBH = laihan.S_ZHANDIANBH;
                tz.S_GUANLIKBH = laihan.S_GUANLIKBH;
                tz.I_SHURUR = LoginInfo.CurrentUser.UserID;
                //获取调整信息
                var ucShenQingXX = Parent.FindControl("UCLHShenQingXX") as UCLHShenQingXX;
                var listSqls = ucShenQingXX.GetSQLS(true);
                tz.I_M1 = listSqls[0];
                tz.I_M2 = listSqls[1];
                tz.I_M3 = listSqls[2];
                tz.I_M4 = listSqls[3];
                tz.I_M5 = listSqls[4];
                tz.I_M6 = listSqls[5];
                tz.I_M7 = listSqls[6];
                tz.I_M8 = listSqls[7];
                tz.I_M9 = listSqls[8];
                tz.I_M10 = listSqls[9];
                tz.I_M11 = listSqls[10];
                tz.I_M12 = listSqls[11];
                tz.I_LIUCHENGBH = liuchengzt;
                //有计划信息才会插入调整信息
                bllT.InsertOrUpdate(tz);
                //下年
                tz.ID = 0;
                listSqls = ucShenQingXX.GetSQLS(false);
                tz.I_M1 = listSqls[0];
                tz.I_M2 = listSqls[1];
                tz.I_M3 = listSqls[2];
                tz.I_M4 = listSqls[3];
                tz.I_M5 = listSqls[4];
                tz.I_M6 = listSqls[5];
                tz.I_M7 = listSqls[6];
                tz.I_M8 = listSqls[7];
                tz.I_M9 = listSqls[8];
                tz.I_M10 = listSqls[9];
                tz.I_M11 = listSqls[10];
                tz.I_M12 = listSqls[11];
                tz.I_Y = Convert.ToInt32(laihan.I_TZY) + 1;
                bllT.InsertOrUpdate(tz);
            }
            else if (LaiHanLX == eLaiHanLX.计划变更 || LaiHanLX == eLaiHanLX.表计因素注销)
            {
                //添加来函附表（计划变更）信息
                //获取步骤信息
                var ucShenQingXX = Parent.FindControl("UCLHShenQingXX_JHBG") as UCLHShenQingXX_JHBG;
                if (LaiHanLX == eLaiHanLX.计划变更)
                {
                    var tz = (YS_LH_JIHUABG)ucShenQingXX.GetSQLS();
                    tz.ID = 0;
                    tz.I_JLZT = 0;
                    tz.S_LAIHANBH = laihan.S_LAIHANBH;
                    tz.S_YONGHUH = laihan.S_YONGHUBH;
                    tz.I_SHURUR = LoginInfo.CurrentUser.UserID;
                    tz.D_SHURURQ = DateTime.Now;
                    tz.I_LIUCHENGBH = liuchengzt;
                    new YS_LH_JIHUABGProcess().InsertOrUpdate(tz);
                }
                else if (LaiHanLX == eLaiHanLX.表计因素注销)
                {
                    var tz = (YS_LH_BIAOJIYSZX)ucShenQingXX.GetSQLS();
                    tz.ID = 0;
                    tz.I_JLZT = 0;
                    tz.S_LAIHANBH = laihan.S_LAIHANBH;
                    tz.S_YONGHUH = laihan.S_YONGHUBH;
                    tz.I_SHURUR = LoginInfo.CurrentUser.UserID;
                    tz.D_SHURURQ = DateTime.Now;
                    tz.I_LIUCHENGBH = liuchengzt;
                    new YS_LH_BIAOJIYSZXProcess().InsertOrUpdate(tz);
                }
            }
            else if (LaiHanLX == eLaiHanLX.计划指标注销)
            {
                //添加来函附表
                var ucShenQingXX = Parent.FindControl("UCLHShenQingXX_JHZBZX") as UCLHShenQingXX_JHZBZX;
                ucShenQingXX.CreateShengQingXX(laihan);
            }
            else if (LaiHanLX == eLaiHanLX.退款)
            {
                var ucinfo = Parent.FindControl("UCLHShenQingXX_TK") as UCLHShenQingXX_TK;
                //添加来函附表（退款步骤）信息                
                ucinfo.GreateLHFB(laihan);
                //生成退款信息
                ucinfo.CreateShengQingXX(laihan);
            }
            else if (LaiHanLX == eLaiHanLX.并户)
            {
                //添加来函附表（计划变更）信息
                var bllT = new YS_LH_BINGHUBLL();
                //获取调整信息
                var ucShenQingXX = Parent.FindControl("UCLHShenQingXX_BH") as UCLHShenQingXX_BH;
                ucShenQingXX.GreateLHFB(laihan);
                ucShenQingXX.CreateShengQingXX(laihan);
            }
            else if (LaiHanLX == eLaiHanLX.销户)
            {
                //添加来函附表（计划变更）信息
                var bllT = new YS_LH_XIAOHUBLL();
                //获取步骤信息
                var tz = new YS_LH_XIAOHU();
                tz.ID = 0;
                tz.I_JLZT = 0;
                tz.S_LAIHANBH = laihan.S_LAIHANBH;
                tz.I_SHURUR = LoginInfo.CurrentUser.UserID;
                tz.D_SHURURQ = DateTime.Now;
                tz.I_SHENPIJG = 1;
                tz.S_SHENPIYJ = liuchengzt == 0 ? "预登记" : "登记";
                tz.I_LIUCHENGBH = liuchengzt;
                bllT.InsertOrUpdate(tz);
            }
            else if (LaiHanLX == eLaiHanLX.销表)
            {
                //添加来函附表（销表流程操作）信息
                var bllT = new YS_LH_XIAOBIAOBLL();
                //获取步骤信息
                var tz = new YS_LH_XIAOBIAO();
                tz.ID = 0;
                tz.I_JLZT = 0;
                tz.S_LAIHANBH = laihan.S_LAIHANBH;
                tz.I_SHURUR = LoginInfo.CurrentUser.UserID;
                tz.D_SHURURQ = DateTime.Now;
                tz.I_SHENPIJG = 1;
                tz.S_SHENPIYJ = liuchengzt == 0 ? "预登记" : "登记";
                tz.I_LIUCHENGBH = liuchengzt;
                bllT.InsertOrUpdate(tz);
                var ucinfo = Parent.FindControl("UCLHShuiBiaoList") as UCLHShuiBiaoList;
                ucinfo.CreateShengQingXX(laihan);
            }
            else if (LaiHanLX == eLaiHanLX.改户)
            {
                var uc = Parent.FindControl("UCLHGaiHuTopInfo") as UCLHGaiHuTopInfo;
                if (uc != null)
                    uc.InsertYongHuXX(laihan);
            }
            else if (LaiHanLX == eLaiHanLX.分户)
            {
                var uc = Parent.FindControl("UCLHFenHuDJXX") as UCLHFenHuDJXX;
                if (uc != null)
                    uc.AddOtherTable(laihan);
                //20190425 多分户添加
                var ucmfh = Parent.FindControl("UCLHShenQingXX_FH") as UCLHShenQingXX_FH;
                if (ucmfh != null)
                    ucmfh.AddOtherTable(laihan);
            }
            else if ((int)LaiHanLX >= 20)
            {
                //添加来函附表信息
                var bllT = new QS_LH_TONGYONGBZYJProcess();
                //获取步骤信息
                var tz = new QS_LH_TONGYONGBZYJ();
                tz.ID = 0;
                tz.I_JLZT = 0;
                tz.S_LAIHANBH = laihan.S_LAIHANBH;
                tz.I_SHURUR = LoginInfo.CurrentUser.UserID;
                tz.D_SHURURQ = DateTime.Now;
                tz.I_SHENPIJG = 1;
                tz.S_SHENPIYJ = liuchengzt == 0 ? "预登记" : "登记";
                tz.I_LIUCHENGBH = liuchengzt;
                bllT.InsertOrUpdate(tz);
                //添加来函内容关联表信息
                if (LaiHanLX == eLaiHanLX.水资源销户)
                {
                    var ucinfo = Parent.FindControl("UCLHJinListQSView") as UCLHJinListQSView;
                    ucinfo.CreateShengQingXX(laihan);
                    UCLHShuiBiaoListView ucinfo2 = Parent.FindControl("UCLHShuiBiaoListView") as UCLHShuiBiaoListView;
                    ucinfo2.CreateShengQingXX(laihan);
                }
                else if (LaiHanLX == eLaiHanLX.水资源表过户)
                {
                    var ucinfo = Parent.FindControl("UCLHShuiBiaoListQS") as UCLHShuiBiaoListQS;
                    ucinfo.CreateShengQingXX(laihan);
                }
                else if (LaiHanLX == eLaiHanLX.水资源并户)
                {
                    var ucinfo = Parent.FindControl("UCLHShenQingXX_BHQS") as UCLHShenQingXX_BHQS;
                    ucinfo.CreateShengQingXX(laihan);
                }
                else if (LaiHanLX == eLaiHanLX.水资源销井 || LaiHanLX == eLaiHanLX.水资源井过户)
                {
                    var ucinfo = Parent.FindControl("UCLHJinInfoQS") as UCLHJinInfoQS;
                    ucinfo.CreateShengQingXX(laihan);
                }
                else if (LaiHanLX == eLaiHanLX.水资源分户)
                {
                    var ucinfo = Parent.FindControl("UCLHFenHuQS") as UCLHFenHuQS;
                    ucinfo.CreateShengQingXX(laihan);
                }
                else if (LaiHanLX == eLaiHanLX.水资源深井类型修改 || LaiHanLX == eLaiHanLX.水资源井性质修改 || LaiHanLX == eLaiHanLX.水资源注销井恢复)
                {
                    ((UCLHJinListQS)Parent.FindControl("UCLHJinListQS")).CreateShengQingXX(laihan);
                    /*
                    var ucinfo = Parent.FindControl("UCLHJinInfo2QS") as UCLHJinInfo2QS;
                    ucinfo.CreateShengQingXX(laihan);
                    */
                }
                else if (LaiHanLX == eLaiHanLX.水资源销表)
                {
                    var ucinfo = Parent.FindControl("UCLHShuiBiaoListQS") as UCLHShuiBiaoListQS;
                    ucinfo.CreateShengQingXX(laihan);
                }
                else if (LaiHanLX == eLaiHanLX.水资源退款)
                {
                    var ucinfo = Parent.FindControl("UCLHTuiKuanInfoQS") as UCLHTuiKuanInfoQS;
                    ucinfo.CreateShengQingXX(laihan);
                }
                else if (LaiHanLX == eLaiHanLX.水资源开采计划)
                {
                    var ucinfo = Parent.FindControl("UCLHKaiCaiJHQS") as UCLHKaiCaiJHQS;
                    ucinfo.CreateShengQingXX(laihan);
                }
                else if (LaiHanLX == eLaiHanLX.水资源采灌计划)
                {
                    var ucinfo = Parent.FindControl("UCLHCaiGuanJHQS") as UCLHCaiGuanJHQS;
                    ucinfo.CreateShengQingXX(laihan);
                }
                else if (LaiHanLX == eLaiHanLX.水资源加价水量调整)
                {
                    var ucinfo = Parent.FindControl("UCLHJIAJIAXXListQS") as UCLHJIAJIAXXListQS;
                    ucinfo.CreateShengQingXX(laihan);
                }
                else if (LaiHanLX == eLaiHanLX.水资源销取水口 || LaiHanLX == eLaiHanLX.水资源取水口过户)
                {
                    var ucinfo = Parent.FindControl("UCLHJinInfoQS") as UCLHJinInfoQS;
                    ucinfo.CreateShengQingXX(laihan);
                    var ucinfo2 = Parent.FindControl("UCLHShuiBiaoListQSK") as UCLHShuiBiaoListQSK;
                    ucinfo2.CreateShengQingXX(laihan);
                }
            }
        }

        //初始化控件
        public void InitControl()
        {
        }

        //验证
        public ValidateRS Validate()
        {
            return new ValidateRS();
        }

        //清除数据
        public void ClearInfo()
        {
        }

        /// <summary>
        ///     加载数据
        /// </summary>
        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            LaiHanID = laihanxx.ID.ToString();

            SetDisplay(laihanxx);
        }

        #endregion
    }
}